<!DOCTYPE html>
<!--
==========================================================================
云捷GO自动生成修改页面代码,只生成一次,按需修改.
生成日期：2021-07-26 15:16:14
生成路径: template/module/news/edit.html
生成人：gfcms
==========================================================================
-->
<html lang="zh">
<head>
    {{template "header" (ossUrl)}}
    <link href="/resource//ajax/libs/datapicker/bootstrap-datetimepicker.min.css" rel="stylesheet"/>
    <link href="/resource/ajax/libs/jasny/jasny-bootstrap.min.css" rel="stylesheet"/>
    <link href="/resource/ajax/libs/summernote/summernote.css" rel="stylesheet"/>
    <link href="/resource/ajax/libs/summernote/summernote-bs3.css" rel="stylesheet"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-news-edit">
        <input name="id" value="{{.news.Id}}" type="hidden">
        <input id="treeId" name="catid" type="hidden" value="{{.menu.Id}}"/>
        <h4 class="form-header h4">基本信息</h4>
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-3 control-label ">栏目名称：</label>
                    <div class="col-sm-8">
                        <div class="input-group">
                            <input class="form-control" type="text" onclick="selectMenuTree()" id="treeName"
                                   readonly="true"
                                   value="{{.menu.Catname}}">
                            <span class="input-group-addon"><i class="fa fa-search"></i></span>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-3 control-label">标题：</label>
                    <div class="col-sm-8">
                        <input name="title" value="{{.news.Title}}" class="form-control" type="text">
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-3 control-label">缩略图：</label>
                    <div class="col-sm-8 fileinput fileinput-new input-group"
                         style="padding-right: 15px;padding-left: 15px;"
                         data-provides="fileinput">
                        <div class="form-control" data-trigger="fileinput">
                            <i class="glyphicon glyphicon-file fileinput-exists"></i>
                            <span class="fileinput-filename">{{.news.Thumb}}</span>
                        </div>
                        <input type="hidden" name="oldimage" value="{{.news.Thumb}}">
                        <span class="input-group-addon btn btn-white btn-file">
                        <span class="fileinput-new">选择文件</span>
                        <span class="fileinput-exists">更改</span>
                        <input type="file" name="thumb">
                    </span>
                        <a href="#" class="input-group-addon btn btn-white fileinput-exists"
                           data-dismiss="fileinput">清除</a>
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-3 control-label">排序：</label>
                    <div class="col-sm-8">
                        <input name="listorder" value="{{.news.Listorder}}" class="form-control" type="text">
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-3 control-label">简介：</label>
                    <div class="col-sm-8">
                        <textarea name="description" class="form-control">{{.news.Description}}</textarea>
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-3 control-label">作者：</label>
                    <div class="col-sm-8">
                        <input name="author" value="{{.news.Author}}" class="form-control" type="text">
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-3 control-label">阅读量：</label>
                    <div class="col-sm-8">
                        <input name="views" value="{{.news.Views}}" class="form-control" type="text">
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-3 control-label">点赞数：</label>
                    <div class="col-sm-8">
                        <input name="zan" value="{{.news.Zan}}" class="form-control" type="text">
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-3 control-label">状态：</label>
                    <div class="col-sm-4">
                        {{getDictTypeRadio "sys_show_hide" "Status" .news.Status}}
                    </div>
                    <div class="col-sm-4">
                        <label class="checkbox-inline check-box">
                            <input type="checkbox" name="top" value="1" {{if eq .news.Top 1}}checked{{end}}>置顶
                        </label>
                        <label class="checkbox-inline check-box">
                            <input type="checkbox" name="indexshow" value="1" {{if eq .news.Indexshow 1}}checked{{end}}>首页显示
                        </label>
                    </div>
                </div>
            </div>
        </div>
        <h4 class="form-header h4">其他信息</h4>
        <div class="row">
                <div class="col-sm-6">
                    <div class="ibox">
                        <div class="ibox-content">
                            <div class="content">{{.news.Content | htmldecode}}</div>
                        </div>
                    </div>
                </div>
        </div>
    </form>
</div>
{{template "footer" (ossUrl)}}
<script src="/resource/ajax/libs/datapicker/bootstrap-datetimepicker.min.js"></script>
<script src="/resource/ajax/libs/jasny/jasny-bootstrap.min.js"></script>
<script src="/resource/ajax/libs/summernote/summernote.js"></script>
<script src="/resource/ajax/libs/summernote/summernote-zh-CN.js"></script>
<script type="text/javascript">
    var prefix = ctx + "module/news";
    $("#form-news-edit").validate({
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            var form = new FormData($("#form-news-edit")[0]);
            //获取新增信息数据
            content = $('.content').summernote('code');
            form.set("content", content);
            $.operate.uploadsave(prefix + "/edit", form);
        }
    }

    /*菜单管理-新增-选择菜单树*/
    function selectMenuTree() {
        var treeId = $("#treeId").val();
        var menuId = treeId > 0 ? treeId : 1;
        var url = "/module/category/selectMenuTree?menuId=" + menuId;
        var options = {
            title: '菜单选择',
            width: "380",
            url: url,
            callBack: doSubmit
        };
        $.modal.openOptions(options);
    }

    function doSubmit(index, layero) {
        var body = layer.getChildFrame('body', index);
        $("#treeId").val(body.find('#treeId').val());
        $("#treeName").val(body.find('#treeName').val());
        layer.close(index);
    }

    function onImageUpload(files) {
        // upload image to server and create imgNode...
        var data = new FormData();
        data.append("file", files[0]);
        _this = this
        $.ajax({
            data: data,
            type: "POST",
            url: prefix + "/upfile", //图片上传出来的url，返回的是图片上传后的路径，http格式
            cache: false,
            contentType: false,
            processData: false,
            dataType: "json",
            success: function (data) {//data是返回的hash,key之类的值，key是定义的文件名
                // console.log(data.data);
                // $('.content').summernote('insertImage', '/upload/' + data.data.url[0], 'img');
                if (data.code === 0) {
                    $(_this).summernote('editor.insertImage', '/upload/' + data.data[0]);
                } else {
                    alert(data.msg);
                }
            },
            error: function () {
                alert("上传失败");
            }
        });
    }

    function onMediaDelete(target) {
        var data = new FormData();
        var url = target.context.attributes.src.value;
        data.append("url", url);
        $.ajax({
            data: data,
            type: "POST",
            url: prefix + "/delfile",
            cache: false,
            contentType: false,
            processData: false,
            success: function (data) {
                console.log(data);
            }
        });
    }

    // 上传视频文件
    function sendVideoFile(files) {
        var data = new FormData();
        data.append("file", files[0]);
        $.ajax({
            type: "POST",
            url: prefix + "/upfile",
            data: data,
            cache: false,
            contentType: false,
            processData: false,
            dataType: 'json',
            beforeSend: function () {
                $.modal.loading("正在上传中，请稍后...");
            },
            success: function (data) {
                // console.log(data)
                if (data.code === 0) {
                    //上传之后的url赋值到 视频地址文本框
                    $(".note-video-url").val("/upload/" + data.data[0]);
                    //去掉插入视频禁用按钮
                    $(".note-video-btn").removeAttr("disabled");
                } else {
                    alert(data.msg);
                }
                $.modal.closeLoading();
            },
            error: function (error) {
                alert("视频上传失败。");
            }
        });
    }


    $('.content').summernote({
        lang: 'zh-CN',
        height: 300,
        minHeight: null,
        maxHeight: null,
        callbacks: {
            onImageUpload: onImageUpload,
            onMediaDelete: onMediaDelete,
            onFileUpload: sendVideoFile,
        }
    });


</script>
</body>
</html>